<?php

namespace App\Models;


class AdminPermission extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'pid', 'title', 'name', 'sort', 'icon', 'type', 'status'
    ];

    /**
     * 关联用户
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function users()
    {
        return $this->belongsToMany(AdminUser::class, 'admin_permission_users', 'permission_id', 'user_id');
    }

    /**
     * 关联角色
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function roles()
    {
        return $this->belongsToMany(AdminRole::class, 'admin_permission_roles', 'permission_id', 'role_id');
    }
}
